package com.yzg.thread;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author misterWei
 * @create 2020年04月09号:21点37分
 * @mailbox forcontinue@163.com
 *
 * 线程开启方式
 */
@Slf4j(topic = "c.thread")
public class ThreadStart1 implements Runnable{

    /**
     * 重写Runnable 接口
     * @param args
     */
    public static void main(String[] args) {
        Thread thread = new Thread(new ThreadStart1(),"thread1");
        thread.start();
        log.info(Thread.currentThread().getName());

    }

    @Override
    public void run() {
        log.info(Thread.currentThread().getName());
    }
    /**
     * 匿名内部类
     */
    @Test
    public void thread1(){
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                log.info(Thread.currentThread().getName());

            }
        },"thread1");

        thread.start();
        log.info(Thread.currentThread().getName());
    }



    /**
     * FutureTask + Callable
     */
    @Test
    public void thread2() throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<Integer>(()->{
            log.info(Thread.currentThread().getName());
            return 1_00;
        });
        Thread thread = new Thread(futureTask,"thread1");
        thread.start();
        Integer integer = futureTask.get();
        log.info(Thread.currentThread().getName());
    }


}
